<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 迭代写法
        /* 
            // 时间O(n) 二叉树退化成链表
            // 空间O(1) 
        */
        var isSameTree = function(p, q) {
            if (!root) return root
            let queue = []
            queue.push(p)
            queue.push(q)
            while (queue.length) {
                // 如果是栈，就是这里先后顺序反一下

                // 拿出左右孩子比较
                let node1 = queue.shift()
                let node2 = queue.shift()

                if (!node1 && !node2) {
                    continue
                }

                if (!node1 || !node2 || node1.val !== node2.val) {
                    return false
                }

                // 和对称二叉树题比，改这里就行
                queue.push(node1.left)
                queue.push(node2.left)
                queue.push(node1.right)
                queue.push(node2.right)
            }
            return true
        };

        function Node(val) {
            this.val = val;
            this.left = null;
            this.right = null;
        }
        var a = new Node(1)
        var b = new Node(2)
        var c = new Node(3)
        var d = new Node(1)
        var e = new Node(2)
        var f = new Node(3)
        // var g = new Node(3)
        a.left = b
        a.right = c
        d.left = e
        d.right = f
        console.log(isSameTree(a, d));
    </script>
</body>
</html>